package com.wk.springboot.retry;

import com.wk.springboot.retry.config.RetryConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Date;

// 自定义重试策略（线性增长）
@Component
public class LinearRetry implements RetryStrategy {

    @Autowired
    RetryConfiguration retryConfiguration;

    @Override
    public Date calculateNextRetryTime(int retryCount, Date lastRetryTime) {
        long interval = retryConfiguration.getInitialInterval() * retryCount;
        return new Date(System.currentTimeMillis() + interval);
    }

    @Override
    public boolean allowRetry(int retryCount) {
        return false;
    }
}